a="ba* and place=leipzig ad and profession=bri*"

def sru2solr(text)
  res=[]
  if !text.include?('=')
    res<< text
  elsif text.split('=').size==2
    if text.split('=')[1].include?('*')
    res << text.split('=')[0]+':'+text.split('=')[1]
else
res << text.split('=')[0]+':"'+text.split('=')[1]+'"'
end
  else
    res<<text.split('=')[0]+':'
    text.split('=')[1..-1].each {|v|
      if v.include?(" and ")
        if v.split('and')[0].include?('*')
        res <<v.split('and')[0].strip
      else
        res <<'"'+ v.split('and')[0].strip+'"'
end
        res << "AND"
        res<<v.split('and')[1]+':'
      else
        if v.include?('*')
          res << v
        else
          res << '"'+v+'"'
        end
      end
    }
  end
  res.join(' ')
end

p sru2solr(a)